perm filename FOO.XGP[ESS,JMC]3 blob
sn#084430 filedate 1974-01-25 generic text, type T, neo UTF8
/FONT#0=BDR25/FONT#1=BDJ25/FONT#2=SUB/FONT#3=NGB25/FONT#4=XMAS25
␈↓␈↓↓␈↓α␈↓β␈↓∧␈↓␈↓ ελRECURSION
␈↓ ↓H
␈↓ ↓H
␈↓ α_The␈α
term␈α
recursion␈α
refers␈α
to␈α
several␈α
related␈α
concepts␈α
in␈α
computer␈α
science␈α
and␈α
mathematics.
␈↓ ↓H
␈↓ ↓H
Recursion relation
␈↓ ↓H
␈↓ ↓H
␈↓ α_One␈α∞or␈α∞more␈α∞functions␈α∞of␈α∞an␈α∞integer␈α∞variable␈α∞is␈α∞defined␈α
by␈α
giving␈α
initial␈α
values␈α
and␈α
by␈α
giving␈α
the
␈↓ ↓Hvalue␈αfor␈αlarger␈αintegers␈α
in␈α
terms␈α
of␈α
smaller␈α
ones.␈α
No␈α
single␈α
definition␈α
is␈α
generally␈α
accepted,␈α
so␈α
we␈α
shall␈α
give
␈↓ ↓Hexamples␈α
of␈α
increasing␈α
complexity.
␈↓ ↓H
␈↓ α_1. The Fibonacci sequence is given by the equations
␈↓ ↓H
␈↓ ↓H
␈↓↓f␈↓α0␈↓↓ = 1
␈↓ ↓H
␈↓ ↓H
f␈↓α1␈↓↓ = 1
␈↓ ↓H
␈↓ ↓H
f␈↓αn+1␈↓↓ = f␈↓αn␈↓↓ + f␈↓αn-1.␈↓
␈↓ ↓H
␈↓ ↓H
␈↓ α_2.␈α
When␈α
differential␈α
equations␈α
are␈α
to␈α
be␈α
solved␈α
numerically,␈α
recursion␈α
relations␈α
such␈α
as
␈↓ ↓H
␈↓↓f(x␈↓α0␈↓↓ + nh) = F(f(x␈↓α0␈↓↓ + (n-1)h) , f(x␈↓α0␈↓↓ + (n-2)h) , . . . , f(x␈↓α0␈↓↓ + (n-k)h))␈↓
␈↓ ↓H
␈↓ ↓H
␈↓ ↓H
arise where ␈↓↓f␈↓ is in general a vector of real numbers.
␈↓ ↓H
␈↓ ↓H
␈↓ α_3.␈α
When␈α
linear␈α
differential␈α
equations␈α
are␈α
solved␈α
by␈α
series,␈α
recursion␈αrelations␈αfor␈αthe␈αcoefficients␈αof
␈↓ ↓Hthe␈α
powers␈α
of␈α
the␈α
independent␈α
variables␈α
arise.
␈↓ ↓H
Recursive functions
␈↓ ↓H
␈↓ ↓H
␈↓ α_The␈α⊃systematic␈α⊃study␈α⊃of␈α⊃recursion␈α⊃began␈α⊃in␈α⊃the␈α⊃1920's␈α⊃when␈α⊃mathematical␈α⊃logic␈α⊂began␈α⊂to␈α⊂treat
␈↓ ↓Hquestions␈αof␈αdefinability,␈αcomputability␈αand␈αdecidability.␈αAn␈αimportant␈αrole␈αis␈αplayed␈αby␈αprimitive␈αrecursive
␈↓ ↓Hfunctions.
␈↓ α_Primitive␈α↔recursive␈α↔functions␈α↔are␈α↔integer␈α↔functions␈α⊗of␈α⊗integers␈α⊗built␈α⊗up␈α⊗from␈α⊗addition␈α⊗and
␈↓ ↓Hmultiplication␈α∞of␈α∞integers␈α∞and␈α∞previously␈α∞defined␈α∞primitive␈α∞recursive␈α∞functions␈α∞by␈α∞the␈α
primitive␈α
recursion
␈↓ ↓Hscheme
␈↓ ↓H
␈↓↓f(0 , x␈↓α2␈↓↓ , . . . , x␈↓αn␈↓↓) = g(x␈↓α2␈↓↓ , . . . , x␈↓αn␈↓↓)
␈↓ ↓H
␈↓ ↓H
␈↓ α_f(x␈↓α1␈↓↓ + 1, x␈↓α2␈↓↓ , . . . , x␈↓αn␈↓↓) = h(f(x␈↓α1␈↓↓ , . . . , x␈↓αn␈↓↓),x␈↓α2␈↓↓, . . . , x␈↓αn␈↓↓n) .␈↓
␈↓ ↓H
␈↓ ↓H
␈↓ α_Here␈α␈↓↓g␈↓␈αand␈α
␈↓↓h␈↓␈α
are␈α
primitive␈α
recursive␈α
functions␈α
of␈α
␈↓↓n-1␈↓␈α
and␈α
␈↓↓n+1␈↓␈α
arguments␈α
respectively.␈α
As␈α
an␈α
example,
␈↓ ↓Hwe␈α
define␈α
␈↓↓n!␈↓␈α
by
␈↓ α_0!␈α
=␈α
1
␈↓ ↓Hand
␈↓ α_␈↓↓(n+1)!␈α
=␈α
(n+1).n!␈↓
␈↓ ↓Hso␈α
that␈α
in␈α
this␈α
case␈α
␈↓↓g␈↓␈α
is␈α
a␈α
function␈α
of␈α
0␈α
arguments,␈α
namely␈α
the␈α
constant␈α
1,␈α
and␈α
␈↓↓h(u,v)␈α
=␈α
(v+1)u.␈↓
␈↓ ↓H
␈↓ α_All␈α∩the␈α∩common␈α⊃functions␈α⊃of␈α⊃number␈α⊃theory␈α⊃are␈α⊃primitive␈α⊃recursive.␈α⊃Moreover,␈α⊃many␈α⊃important
␈↓ ↓Hfunctions␈αon␈αother␈αcountable␈αdomains␈αthan␈αthe␈αintegers␈α
correspond␈α
to␈α
primitive␈α
recursive␈α
functions␈α
when␈α
we
␈↓ ↓Hchoose␈α
a␈α
specific␈α
enumeration␈α
for␈α
the␈α
domain.
␈↓ ↓H
␈↓ α_Primitive␈α∞recursive␈α∞functions␈α∞are␈α∞included␈α∞in␈α∞general␈α∞recursive␈α
functions.␈α
The␈α
definition␈α
of␈α
general
␈↓ ↓Hrecursive␈α
function␈α
is␈α
like␈α
that␈α
given␈α
above␈α
for␈α
primitive␈α
recursive␈α
functions␈α
except␈α
that␈α
the␈α
relations␈α
are
␈↓ ↓Hreplaced␈αby␈αan␈αarbitrary␈αfinite␈αcollection␈αof␈αequations␈αrelating␈αthe␈αvalues␈αof␈α␈↓↓f␈↓␈αfor␈αdifferent␈αarguments,␈αand
␈↓ ↓Hthe␈αfunction␈αis␈αconsidered␈αdefined␈α␈↓βif␈αand␈αonly␈αif␈↓␈αa␈αunique␈αvalue␈αof␈α␈↓↓f(x␈↓α1␈↓↓␈α,␈α.␈α.␈α.␈α,␈αx␈↓αn␈↓↓)␈↓␈αcan␈αbe␈αdeduced␈αfrom␈αthe
␈↓ ↓Hequations␈αfor␈αeach␈α␈↓↓n␈↓-tuplet␈α␈↓↓(x␈↓α1␈↓↓␈α,␈α.␈α.␈α.␈α,␈αx␈↓αn␈↓↓)␈↓.␈αNaturally,␈αif␈αsomeone␈αgives␈αyou␈αan␈αarbitrary␈αcollection␈αof␈αsuch
␈↓ ↓Hrelations,␈αyou␈αmay␈αnot␈αbe␈αable␈αto␈αdetermine␈αwhether␈α␈↓↓f(x␈↓α1␈↓↓␈α,␈α.␈α.␈α.␈α,␈αx␈↓αn␈↓↓)␈↓␈αis␈αuniquely␈α
determined,␈α
so␈α
you␈α
may␈α
not
␈↓ ↓Hknow␈αwhether␈αyou␈αhave␈αa␈αgeneral␈αrecursive␈αfunction␈αor␈αnot.␈αThis␈αdifficulty␈αis␈αunavoidable.␈αThere␈αis␈αno␈αway
␈↓ ↓Hto␈αgive␈αa␈αdefinition␈αscheme␈αthat␈αis␈αalways␈αguaranteed␈αto␈αgive␈αa␈αfunction␈αbut␈αwhich␈αwill␈αgive␈αall␈α
computable
␈↓ ↓Hfunctions.␈α∞This␈α∞fact␈α∞is␈α∞itself␈α∞expressed␈α∞in␈α∞the␈α∞terminology␈α∞of␈α∞recursive␈α∞function␈α∞theory␈α∞by␈α∞the␈α
statement
␈↓ ↓Hthat␈αthe␈αset␈αof␈αcomputable␈αfunctions␈αis␈αrecursively␈αenumerable␈αbut␈αnot␈αrecursive.␈αThe␈αfamous␈αexample␈αof␈αa
␈↓ ↓Hgeneral␈α∩recursive␈α∩function␈α∩that␈α∩is␈α∩not␈α∩primitive␈α∩recursive␈α∩is␈α∩the␈α∩Ackermann␈α∩function␈α∩defined␈α∩by␈α∩the
␈↓ ↓Hequations
␈↓ ↓H
␈↓ α_␈↓↓A(0,n,p) = n + p,
␈↓ ↓H
␈↓ α_A(1,0,p) = 0,
␈↓ ↓H
␈↓ α_A(2,0,p) = 1,
␈↓ ↓H
␈↓ α_A(m+1,0,p) = p ␈↓if ␈↓↓p␈↓ > 1, and
␈↓ ↓H
␈↓ α_A(m+1,n+1,p) = A(m,A(m+1,n,p),p).␈↓
␈↓ ↓H
␈↓ ↓H
␈↓ α_An␈α∞important␈α∞result␈α∞for␈α∞computer␈α
science␈α
is␈α
that␈α
the␈α
general␈α
recursive␈α
functions␈α
coincide␈α
with␈α
the
␈↓ ↓Hfunctions␈α∞defined␈α∞by␈α∞Turing␈α∞machines␈α∞which␈α∞are␈α∞a␈α∞simple␈α
form␈α
of␈α
computer.␈α
They␈α
also␈α
coincide␈α
with␈α
the
␈↓ ↓Hfunctions␈α⊂of␈α⊂integers␈α⊂defined␈α⊂by␈α⊂Algol␈α⊂or␈α⊂Fortran␈α⊂programs␈α⊂assuming␈α⊂that␈α⊂the␈α⊂program␈α∂can␈α∂cope␈α∂with
␈↓ ↓Hwhatever␈α
size␈α
integers␈α
arise.
␈↓ ↓H
␈↓ α_Both␈α∀programs␈α∀and␈α∀general␈α∀recursion␈α∀schemata␈α∀in␈α∀general␈α∀give␈α∪partial␈α∪functions,␈α∪because␈α∪the
␈↓ ↓Hcomputation␈α
may␈α
terminate␈α
for␈α
some␈α
values␈α
of␈α
the␈α
arguments␈α
and␈α
not␈α
for␈α
others.
␈↓ ↓H
␈↓ α_The␈α
study␈α
of␈α
computable␈α
functions␈α
is␈α
the␈α
domain␈α
of␈α
recursive␈α
function␈α
theory,␈α
an␈αactive␈αbranch␈αof
␈↓ ↓Hmathematics.␈αThe␈αconnection␈αbetween␈αcurrent␈αresearch␈αin␈αrecursive␈αfunction␈αtheory␈αand␈αcomputing␈αpractice
␈↓ ↓Hor␈α∂even␈α∂current␈α∂research␈α∂in␈α∞computer␈α∞science␈α∞is␈α∞rather␈α∞tenuous.␈α∞This␈α∞situation␈α∞might␈α∞change␈α∞because␈α∞of
␈↓ ↓Hdevelopments␈α
in␈α
either␈α
field.
␈↓ ↓H
␈↓ ↓H
Recursive procedures
␈↓ ↓H
␈↓ ↓H
␈↓ α_In␈αprogramming,␈αit␈αis␈αfrequently␈αconvenient␈αto␈αhave␈αa␈αprocedure␈αuse␈αitself␈αas␈αa␈αsubprocedure.␈αIf␈αthe
␈↓ ↓Hprocedure␈α∂does␈α∂this,␈α∂it␈α∂is␈α∂called␈α∂recursive.␈α∂Recursive␈α∂procedures␈α∞are␈α∞particularly␈α∞natural␈α∞in␈α∞dealing␈α∞with
␈↓ ↓Hsymbolic␈αexpressions,␈αbecause␈αthe␈αstructure␈αof␈αthe␈αprograms␈αoften␈αmatch␈αthe␈αstructure␈αof␈αthe␈αdata.␈αAs␈αfar
␈↓ ↓Has␈α⊃programming␈α⊃languages␈α⊃are␈α⊃concerned,␈α⊃recursive␈α⊃procedures␈α⊃are␈α⊃quite␈α⊃natural;␈α⊂it␈α⊂requires␈α⊂a␈α⊂special
␈↓ ↓Hstatement␈α∞in␈α∞the␈α∞definition␈α∞of␈α∞the␈α∞language␈α∞to␈α∞forbid␈α∞them.␈α∞However,␈α∞implementing␈α
them␈α
requires␈α
that␈α
a
␈↓ ↓Hspecial␈α
kind␈α
of␈α
object␈α
code␈α
be␈α
compiled,␈α
and␈α
early␈α
programming␈α
languages␈α
like␈α
Fortran␈α
don't␈α
allow␈α
them.␈α
The
␈↓ ↓Hproblem␈α
is␈α
that␈α
variables␈αin␈αthe␈αprogram␈αcorrespond␈αto␈αlocations␈αin␈αthe␈αmachine,␈αand␈αwhen␈αthe␈αprogram␈αis
␈↓ ↓Hcalled␈α∂by␈α∂itself,␈α∂it␈α∂will␈α∂use␈α∂these␈α∂same␈α∂locations␈α∂forgetting␈α∂their␈α∂previous␈α∂contents.␈α∞Therefore,␈α∞recursive
␈↓ ↓Hprograms␈αuse␈αan␈αarray,␈αcalled␈αthe␈α␈↓↓stack␈↓␈αto␈αstore␈αthe␈αcontents␈αof␈αregisters␈αthat␈αmust␈αbe␈αsaved.␈αThis␈αstorage
␈↓ ↓Hcan␈α∂be␈α∂done␈α∂by␈α∂the␈α∞calling␈α∞routine␈α∞before␈α∞it␈α∞enters␈α∞the␈α∞subroutine␈α∞or␈α∞it␈α∞can␈α∞be␈α∞done␈α∞by␈α∞the␈α∞subroutine
␈↓ ↓Hbefore␈α
it␈α
uses␈α
the␈α
registers,␈α
the␈α
latter␈α
being␈α
more␈α
common.␈α
After␈α
the␈α
registers␈α
have␈α
been␈α
saved␈α
on␈α
the␈α
stack,
␈↓ ↓Hthe␈α
index␈α
into␈α
the␈α
stack␈α
is␈α
increased␈α
by␈α
the␈α
number␈α
of␈α
registers␈α
stored␈α
so␈α
that␈α
subsequent␈α
saving␈α
on␈αthe
␈↓ ↓Hstack␈α
will␈α
use␈α
fresh␈α
registers.␈α
When␈α
the␈α
subroutine␈α
exits␈α
the␈α
contents␈α
of␈α
the␈α
saved␈α
registers␈α
are␈αrestored
␈↓ ↓Hfrom␈α
the␈α
stack␈α
to␈α
their␈α
previous␈α
values␈αand␈αthe␈αstack␈αpointer␈αis␈αreduced␈αby␈αthe␈αamount␈αit␈αwas␈αpreviously
␈↓ ↓Hincreased.␈αThis␈αis␈αdone␈αby␈αthe␈αcaller␈αor␈αby␈αthe␈αsubroutine␈αaccording␈αto␈αwhether␈αthe␈α
caller␈α
or␈α
subroutine␈α
did
␈↓ ↓Hthe␈αoriginal␈αstoring.␈αAn␈αalternative␈αtechnique␈αis␈αto␈αuse␈αthe␈αstack␈αfor␈αall␈αtemporary␈αregisters.␈α
In␈α
this␈α
case,␈α
it
␈↓ ↓His␈α
unnecessary␈α
to␈αmove␈αdata␈αaround␈αand␈αit␈αis␈αonly␈αnecessary␈αto␈αchange␈αthe␈αstack␈αpointer␈αwhen␈αsubroutines
␈↓ ↓Hare␈αentered␈αand␈αleft.␈αHowever,␈αthis␈αtechnique␈αuses␈αup␈αthe␈αindexing␈αcapabilities␈αof␈αsome␈αmachines␈αwhich␈αmay
␈↓ ↓Hbe␈α∪wanted␈α∪for␈α∪other␈α∪purposes.␈α∩Recursive␈α∩programs␈α∩can␈α∩be␈α∩written␈α∩in␈α∩any␈α∩programming␈α∩language␈α∩by
␈↓ ↓Hexplicitly␈α
programming␈α
the␈α
saving␈α
and␈α
restoring.
␈↓ α_The␈αfirst␈αlanguage␈αto␈αuse␈α
recursive␈α
subroutines␈α
on␈α
a␈α
regular␈α
basis␈α
were␈α
the␈α
IPL␈α
languages␈α
of␈α
Newell,
␈↓ ↓HShaw␈α∂and␈α∂Simon.␈α∂Lists␈α∂were␈α∞used␈α∞for␈α∞the␈α∞stack␈α∞and␈α∞the␈α∞saving␈α∞and␈α∞restoring␈α∞was␈α∞done␈α∞explicitly␈α∞by␈α∞the
␈↓ ↓Hprogrammer.␈α
The␈α
first␈αlanguage␈αprovide␈αan␈αautomatic␈αmechanism␈αfor␈αrecursion␈αwas␈αLISP.␈αAlgol␈α60␈αand␈αits
␈↓ ↓Hsuccessors␈α
allow␈α
recursion.
␈↓ α_Many␈αcomputers␈αhave␈αspecial␈αinstruction␈αfor␈αhandling␈αstacks,␈αe.g.␈αthe␈αPUSH␈αand␈αPOP␈αinstructions␈αof
␈↓ ↓Hthe␈α⊃Digital␈α⊃Equipment␈α⊃PDP-10.␈α⊃Other␈α⊃machines,␈α⊃such␈α⊃as␈α⊃the␈α⊂Burroughs␈α⊂5000␈α⊂and␈α⊂its␈α⊂successors,␈α⊂have
␈↓ ↓Hinstructions␈α⊃that␈α⊃use␈α⊃a␈α⊃hardware␈α⊃stack␈α⊃directly.␈α⊃These␈α⊃special␈α⊃facilities␈α⊃give␈α⊃a␈α⊂modest␈α⊂increase␈α⊂in␈α⊂the
␈↓ ↓Hefficiency␈α
of␈α
recursive␈α
programming.
␈↓ ↓H
␈↓ ↓H
Recursive conditional expressions
␈↓ ↓H
␈↓ ↓H
␈↓ α_The␈αrecursive␈αuse␈αof␈αconditional␈αexpressions␈αprovides␈αan␈αeconomical␈α
and␈α
elegant␈α
way␈α
of␈α
specifying␈α
the
␈↓ ↓Hfunctions␈αthat␈αare␈αcomputable␈αin␈αterms␈αof␈αa␈αcollection␈αof␈αbase␈αfunctions.␈αThis␈αtechnique␈αis␈αthe␈αbasis␈αof␈αthe
␈↓ ↓HLISP␈α
programming␈α
language␈α
and␈α
also␈α
of␈α
the␈α
theoretical␈α
system␈α
of␈αD.␈αScott␈αfor␈αstudying␈αthe␈αproperties␈αof
␈↓ ↓Hcomputer␈α
programs.
␈↓ ↓H
␈↓ α_A conditional expression has the form, in Algol notation, of
␈↓ ↓H
␈↓ ↓H
␈↓ ↓H
␈↓βif ␈↓↓p ␈↓βthen ␈↓↓a ␈↓βelse ␈↓↓b␈↓.
␈↓ ↓H
␈↓ ↓H
␈↓ ↓HIt␈αis␈αevaluated␈αby␈αfirst␈αevaluating␈αthe␈αpropositional␈αexpression␈α␈↓↓p␈↓.␈αIf␈α␈↓↓p␈↓␈αis␈α␈↓βtrue␈↓,␈αthe␈αvalue␈αof␈αthe␈αconditional
␈↓ ↓Hexpression␈αis␈αthat␈αof␈α␈↓↓a␈↓,␈αand␈αif␈αthe␈αvalue␈αof␈α␈↓↓p␈↓␈αis␈α␈↓βfalse␈↓,␈αthe␈αvalue␈αof␈αthe␈α
conditional␈α
expression␈α
is␈α
that␈α
of␈α
␈↓↓b␈↓.␈α
It
␈↓ ↓His␈α
important␈α
to␈α
note␈α
that␈α
only␈α
one␈α
of␈α
␈↓↓a␈↓␈α
or␈α
␈↓↓b␈↓␈α
is␈α
actually␈α
evaluated.
␈↓ α_A␈α
simple␈α
example␈α
of␈α
the␈α
use␈α
of␈α
conditional␈α
expressions␈α
is␈α
to␈α
define␈α
the␈α
absolute␈α
value␈α
of␈α
a␈α
number␈α
by
␈↓ ↓H
␈↓ α_␈↓↓|x| = ␈↓βif␈↓↓ x < 0 ␈↓βthen␈↓↓ -x ␈↓βelse␈↓↓ x.␈↓
␈↓ ↓H
␈↓ ↓H
␈↓ α_Conditional␈α
expressions␈α
are␈α
used␈α
to␈α
define␈α
functions␈α
recursively␈α
by␈α
writing␈α
the␈α
definition␈α
in␈α
the␈α
form
␈↓ ↓H
␈↓ α_␈↓↓f(x , . . . , z) ← ␈↓∧E␈↓↓{x , . . . , z, f , g , . . . , h}␈↓,
␈↓ ↓H
␈↓ ↓H
␈↓ ↓Hwhere␈α
␈↓∧E␈↓␈α
is␈α
an␈α
expression␈α
involving␈α
the␈α
variables,␈↓↓x␈α
,␈α
.␈α
.␈α
.␈α
,␈α
z␈↓,␈α
the␈α
function␈α␈↓↓f␈↓␈αbeing␈αdefined,␈αand␈αknown␈αor
␈↓ ↓Hpreviously␈α
defined␈α
functions␈α
␈↓↓g␈α
,␈α
.␈α
.␈α
.␈α
,␈α
h␈↓.
␈↓ α_An␈α
example␈α
of␈α
such␈α
a␈α
definition␈α
is
␈↓ ↓H
(␈↓↓a␈↓)␈↓ α_␈↓↓n! ← ␈↓βif␈↓↓ n = 0 ␈↓βthen␈↓↓ 1 ␈↓βelse␈↓↓ n.(n-1)!␈↓.
␈↓ ↓H
␈↓ ↓H
␈↓ α_The␈αgeneral␈αmethod␈αfor␈αevaluating␈αrecursive␈αconditional␈αexpressions␈αis␈αillustrated␈αby␈αusing␈αthe␈α
above
␈↓ ↓Hdefinition␈α
to␈α
evaluate␈α
3!.␈α
Namely,␈α
we␈α
have
␈↓ ↓H
3! = ␈↓βif␈↓↓ 3=0 ␈↓βthen ␈↓↓1 ␈↓βelse ␈↓↓3.(3-1)!
␈↓ ↓H
␈↓ α_ = 3.2! =3.(␈↓βif␈↓↓ 2=0 ␈↓βthen ␈↓↓1 ␈↓βelse ␈↓↓2.(2-1)!)
␈↓ ↓H
␈↓ α_ = 3.2.(␈↓βif ␈↓↓1=0 ␈↓βthen ␈↓↓1 ␈↓βelse ␈↓↓1.(1-1)!)
␈↓ ↓H
␈↓ α_ = 3.2.1.(␈↓βif ␈↓↓0=0 ␈↓βthen ␈↓↓1 ␈↓βelse ␈↓↓0.(0-1)!)
␈↓ ↓H
␈↓ α_ = 3.2.1.1 = 6.␈↓
␈↓ ↓H
␈↓ ↓H
␈↓ ↓HNote␈α⊂that␈α⊂the␈α⊂rule␈α⊂for␈α⊂evaluating␈α⊂conditional␈α⊂expressions␈α⊂ensures␈α∂that␈α∂the␈α∂computer␈α∂never␈α∂attempts␈α∂to
␈↓ ↓Hevaluate␈α
(-1)!.␈α
This␈α
is␈α
necessary␈α
since␈α
its␈α
evaluation␈α
wouldn't␈α
terminate.
␈↓ α_As␈α
a␈α
second␈α
example,␈α
the␈α
Ackermann␈α
function␈α
mentioned␈α
above␈αis␈αwritten␈αas␈αa␈αrecursive␈αconditional
␈↓ ↓Hexpression␈α
as␈α
follows:
␈↓ ↓H
␈↓ α_␈↓↓A(m,n,p) ←
␈↓ ↓H
␈↓ α_␈↓ αh␈↓βif ␈↓↓m = 0 ␈↓βthen ␈↓↓n + p
␈↓ ↓H
␈↓ α_␈↓ αh␈↓βelse if ␈↓↓n = 0 ␈↓βthen ␈↓↓(␈↓βif ␈↓↓m = 1 ␈↓βthen ␈↓↓0␈↓β else if ␈↓↓m = 2 ␈↓βthen ␈↓↓1␈↓β else ␈↓↓p)
␈↓ ↓H
␈↓ α_␈↓ αh␈↓βelse ␈↓↓A(m - 1,A(m,n - 1,p),p).␈↓
␈↓ ↓H
␈↓ ↓H
␈↓ α_Several␈α
remarks␈α
are␈α
worth␈α
making:
␈↓ α_First,␈α∪in␈α∪a␈α∪programming␈α∩language␈α∩that␈α∩uses␈α∩recursive␈α∩conditional␈α∩expressions,␈α∩3!␈α∩would␈α∩not␈α∩be
␈↓ ↓Hevaluated␈αby␈αthe␈αabove␈αsymbolic␈αmanipulation.␈αEither␈α␈↓↓(a)␈↓␈αwould␈αbe␈αcompiled␈α
into␈α
a␈α
recursive␈α
subroutine␈α
(i.e.
␈↓ ↓Ha␈αsubroutine␈αof␈αthe␈αtype␈αexplained␈αabove␈αthat␈αcalls␈αitself␈αand␈αuses␈αa␈αstack␈αto␈αsave␈αintermediate␈αresults␈αand
␈↓ ↓Hreturn␈α
addresses)␈α
or␈α
a␈α
recursive␈α
interpreter␈α
would␈α
interpret␈α
a␈α
list␈α
structure␈α
version␈α
of␈α
␈↓↓(a)␈↓.
␈↓ α_Second,␈α␈↓↓(a)␈↓␈αcan␈αeasily␈αbe␈αreplaced␈αby␈αanother␈αexpression␈αfor␈αthe␈αfactorial␈αthat␈αcan␈αbe␈αcompiled␈αinto␈αa
␈↓ ↓Hnon-recursive␈α
program.␈α
Namely,␈α
we␈α
write
␈↓ ↓H
(␈↓↓b␈↓)␈↓ α_␈↓↓n! ← fact(n, 0, 1)␈↓
␈↓ ↓H
␈↓ ↓H
where
␈↓ ↓H
␈↓ ↓H
␈↓ α_␈↓↓fact(n, m, p) ← ␈↓βif␈↓↓ m = n ␈↓βthen ␈↓↓p ␈↓βelse ␈↓↓fact(n, m+1,(m+1)p).
␈↓ ↓H
␈↓ ↓H
␈↓ ↓H(b)␈α
␈↓can␈αbe␈αtranslated␈αinto␈αa␈αnon-recursive␈αprogram,␈αbecause␈αthe␈αonly␈αoccurrence␈αof␈α␈↓↓fact␈↓␈αon␈αthe␈αright␈αhand
␈↓ ↓Hside␈αof␈αthe␈αdefinition␈αappears␈αat␈αthe␈αouter␈αlevel,␈αi.e.␈α␈↓↓fact(n,␈αm+1,(m+1)p)␈↓␈αgives␈αthe␈αvalue␈αof␈α␈↓↓fact(n,␈αm,␈αp)␈α␈↓in
␈↓ ↓Hcontrast␈αto␈αthe␈αthe␈αsituation␈αin␈α␈↓↓(a)␈α␈↓where␈α␈↓↓(n-1)!␈α␈↓must␈αbe␈αmultiplied␈αby␈α␈↓↓n␈α␈↓to␈αgive␈α␈↓↓n!.␈α␈↓This␈αallows␈αthe␈αobject
␈↓ ↓Hprogram␈α∂to␈α∂contain␈α∂an␈α∂ordinary␈α∂jump␈α∂to␈α∂itself␈α∂rather␈α∂than␈α∂a␈α∞subroutine␈α∞call.␈α∞When␈α∞this␈α∞is␈α∞possible,␈α∞the
␈↓ ↓Hfunction␈α⊃definition␈α⊃is␈α⊃called␈α⊃iterative.␈α⊃Thus␈α⊃␈↓↓fact␈↓␈α⊃is␈α⊃iterative␈α⊃while␈α⊃the␈α⊂definition␈α⊂␈↓↓(a)␈α⊂␈↓is␈α⊂not.␈α⊂Recursive
␈↓ ↓Hdefinitions␈αcannot␈αin␈αgeneral␈αbe␈αreplaced␈αby␈αiterative␈αdefinitions␈αexcept␈αby␈αencoding␈αthe␈αstack␈αas␈αa␈αvariable
␈↓ ↓Hin␈α
the␈α
program,␈α
and␈α
if␈α
this␈α
has␈α
to␈α
be␈α
done,␈α
there␈α
is␈α
no␈α
advantage␈α
in␈α
the␈α
replacement.
␈↓ α_Third,␈αthere␈αmay␈αbe␈αseveral␈αoccurrences␈αof␈αthe␈αfunction␈αbeing␈αdefined␈αon␈αthe␈αright␈αhand␈αside␈αof␈αthe
␈↓ ↓Hrecursive␈α∞definition,␈α∞and␈α∞whether␈α∞the␈α∞evaluation␈α∞terminates␈α∞may␈α∞depend␈α
on␈α
which␈α
occurrence␈α
is␈α
evaluated
␈↓ ↓Hfirst.␈α
The␈α
following␈α
example␈α
due␈α
to␈α
Morris␈α
shows␈α
this:
␈↓ ↓H
␈↓ α_␈↓↓f(x,y) ← ␈↓βif ␈↓↓x=0 ␈↓βthen ␈↓↓0 ␈↓βelse ␈↓↓f(x-1 , f(y-2, x)).␈↓
␈↓ ↓H
␈↓ ↓H
␈↓ ↓HThe␈α
reader␈α
should␈α
evaluate␈α
␈↓↓f(2,1)␈↓␈α
to␈α
convince␈α
himself.
␈↓ α_It␈αis␈αalso␈αpossible␈αto␈αuse␈αrecursive␈αconditional␈αexpressions␈αto␈αdefine␈αfunctions␈αthat␈αtake␈αfunctions␈αas
␈↓ ↓Harguments␈α⊃or␈α⊃give␈α⊃functions␈α⊂as␈α⊂results.␈α⊂However,␈α⊂there␈α⊂remain␈α⊂unsolved␈α⊂problems␈α⊂in␈α⊂getting␈α⊂compiling
␈↓ ↓Halgorithms␈α
that␈α
give␈α
efficient␈α
object␈α
code␈α
and␈α
give␈α
the␈α
"right"␈α
answers␈α
in␈α
all␈α
cases.
␈↓ α_The␈αterm␈α␈↓↓recursive␈↓␈αis␈αalso␈αsometimes␈αapplied␈αto␈αthe␈αthe␈αBackus-Naur␈αform␈αused␈αto␈αdefine␈αclasses␈αof
␈↓ ↓Hstrings␈α
of␈α
symbols.